package orbitPrototype.loaders;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.imageio.ImageIO;

import orbitPrototype.Settings;

public class SpriteSheetLoader 
{	
	private static Map<String, BufferedImage> _loadedSheets = new HashMap<String, BufferedImage>();
	
	private static final String FILE_ENDING = ".png";
	
	public SpriteSheetLoader()
	{
		
	}
	
	public static BufferedImage getSheet(String sheetName)
	{
		BufferedImage sheetImage = null;
		
		if((sheetImage = _loadedSheets.get(sheetName)) != null)
		{
			return sheetImage;
		}
		else
		{
			String path = Settings.PATH_SPRITES + sheetName + FILE_ENDING;
			
			try
			{
				System.out.println("Loading spritesheet: " + path + "...");
				sheetImage = ImageIO.read(new File(path));
			}
			catch(IOException e)
			{
				System.out.println("Failed loading spritesheet: " + path);
				System.out.println(e);
			}
			
			_loadedSheets.put(sheetName, sheetImage);
			
			return sheetImage;
		}
	}
}
